package com.hongsen.cn.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.FragmentTransaction;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.hongsen.cn.Utils.LogUtil;
import com.hongsen.cn.Utils.RxBus;
import com.hongsen.cn.Utils.ToastUtils;
import com.hongsen.cn.adapter.GetOutOfLineAdapter;
import com.hongsen.cn.base.BaseActivity;
import com.hongsen.cn.base.BaseFragment;
import com.hongsen.cn.bean.RxValue;
import com.hongsen.cn.bean.TheKeyPersonelBean;
import com.hongsen.cn.contract.ForAShortTimeView;
import com.hongsen.cn.dayandmonth.R;
import com.hongsen.cn.dayandmonth.databinding.FragmentForAShortTimeBinding;
import com.hongsen.cn.listener.OnItemClickListener;
import com.hongsen.cn.presenter.ForAShortTimePresenter;

import java.util.ArrayList;
import java.util.List;

import static com.hongsen.cn.bean.RxBusEventKey.HIDE_FRAGMENT_AND_SHOW;

/**
 * 警情定位
 */
public class ForAShortTimeFragment extends BaseFragment<ForAShortTimePresenter> implements ForAShortTimeView, View.OnClickListener {

    private FragmentForAShortTimeBinding binding;
    public List<TheKeyPersonelBean> list = new ArrayList<>();
    public GetOutOfLineAdapter adapter;


    @Override
    protected ForAShortTimePresenter createPresenter() {
        return new ForAShortTimePresenter(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_for_a_short_time;
    }

    @Override
    protected void initToolbar(Bundle savedInstanceState) {

    }

    @Override
    protected void initData() {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(LayoutInflater.from(getActivity())
                , R.layout.fragment_for_a_short_time, null, false);
        binding.setFragment(this);
        initView();
        presenter = new ForAShortTimePresenter(this);
        presenter.getTheKeyPersonel("4");
        return binding.getRoot();
    }

    private void initView() {
        binding.rlModule.setLayoutManager(new LinearLayoutManager(getActivity()));
        binding.rlModule.setItemAnimator(new DefaultItemAnimator());
        adapter = new GetOutOfLineAdapter(getActivity(), list,"4");
        binding.rlModule.setAdapter(adapter);
        adapter.setOnItemClickLitener(new OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {

            }

            @Override
            public void onItemLongClick(View view, int position) {

            }
        });

        binding.btnBack.setOnClickListener(this);
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        if (!hidden) {
        }
    }

    /**
     * @param type
     */
    @Override
    public void getTheKeyPersonel(String type, final List<TheKeyPersonelBean> listBeans) {
        list.addAll(listBeans);
        adapter.notifyDataSetChanged();
        binding.tvModuleTitle.setText("出所人员("+ list.size() + "）");
    }


    @Override
    public void onClick(View v) {
        int sS_ID = v.getId();
        if (sS_ID == R.id.btnBack) {
            RxBus.getDefault().post(new RxValue(HIDE_FRAGMENT_AND_SHOW,"1"));
        }
    }

}
